$('#a').click(function () {
    console.log('44');
    return false;
});
$('body').on('click','.edit',function(){
    console.log('---');
    $.ajax({
        url: '/index.php?s=api/edit/edit_list',
        type:'POST',
        data:{
        },
        success:function(value){
            window.location.href = '/index.php?s=index/login/login_list';
        }
    });
});
$('#add-btn').click(function () {
    //题目
    let subject = [];
    let fractionLift = [];
    let fractionRight = [];
    let explain = '';
    let theme = '';
    $('.explain').each(function(){
        explain = this.value;
    });
    $('.theme').each(function(){
        theme = this.value;
    });
    $('.subject').each(function(){
        subject.push(this.value);

    });
    //分数
    $('.fraction_lift').each(function(){

        fractionLift.push(this.value);
    });
    $('.fraction_right').each(function(){

        fractionRight.push(this.value);
    });

    // console.log(explain,theme);
    $.ajax({
        url:'/index.php?s=api/homepage/homepage_motif',
        type:'POST',
        data:{
            theme:theme,
            explain:explain,
            topic:subject,
            lift:fractionLift,
            right:fractionRight
        },
        success:function (value) {
            console.log(value);
        }
    });

});
$('.button_edit').click(function(){

    //添加提示框
    let html = '<!-- 提示框 -->\n' +
        '                    <div class="modal fade" id="staticBackdrop" data-backdrop="static" data-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true">\n' +
        '                        <div class="modal-dialog modal-dialog-centered">\n' +
        '                            <div class="modal-content">\n' +
        '                                <div class="modal-header">\n' +
        '                                    <h5 class="modal-title" id="staticBackdropLabel">问卷名称</h5>\n' +
        '                                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">\n' +
        '                                        <span aria-hidden="true">&times;</span>\n' +
        '                                    </button>\n' +
        '                                </div>\n' +
        '                                <div class="modal-body">\n' +
        '                                    <input type="text" class="name" style="width: 100%; height: 50px;border: 1px solid #00A7EA; border-radius: 4px;"/>\n' +
        '                                </div>\n' +
        '                                <div class="modal-footer">\n' +
        '                                    <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>\n' +
        '                                    <button type="button" class="btn btn-primary homepage_name">保存</button>\n' +
        '                                </div>\n' +
        '                            </div>\n' +
        '                        </div>\n' +
        '                    </div>\n' +
        '                    <!--  -->';

        $(this).after(html);
        //点击保存
    $('.homepage_name').click(function(){
        //题目
        let subject = [];
        //分数
        let fractionLift = [];
        let fractionRight = [];
        //主题说明
        let explain = '';
        //主题
        let theme = '';
        //问卷名称
        let name = '';
        $('.explain').each(function(){
            explain = this.value;
        });
        $('.theme').each(function(){
            theme = this.value;
        });
        $('.subject').each(function(){
            subject.push(this.value);

        });
        //分数
        $('.fraction_lift').each(function(){

            fractionLift.push(this.value);
        });
        $('.fraction_right').each(function(){

            fractionRight.push(this.value);
        });
        //问卷名称
        $('.name').each(function () {
            name = this.value;
        });


        // console.log(explain,theme);
        $.ajax({
            url:'/index.php?s=api/homepage/homepage_motif',
            type:'POST',
            data:{
                theme:theme,
                explain:explain,
                topic:subject,
                lift:fractionLift,
                right:fractionRight,
                name:name
            },
            success:function (value) {
                console.log(value);
                if(value.status === 0){
                    window.alert(value.message);
                    window.location.href ='/index.php?s=index/homepage/homepage_preview/motif_id/'+theme;
                }else{
                    window.alert(value.message);
                }
            }
        });
    });
});
